package cn.pugle.oj.leetcode;

import cn.pugle.oj.catalog.TreeProblem;

/**
 * @author tzp
 * @since 2020/10/13
 */
public class LC617 implements TreeProblem {
    public TreeNode mergeTrees(TreeNode t1, TreeNode t2) {
        if (t1 == null || t2 == null) {
            return t1 == null ? t2 : t1;
        }
        t1.val = t1.val + t2.val;
        t1.left = mergeTrees(t1.left, t2.left);
        t1.right = mergeTrees(t1.right, t2.right);
        return t1;
    }

    public static void main(String[] args) {
        TreeNode a = TreeNode.arrayToTreeNode(new Integer[]{1, 3, 2, 5});
        TreeNode b = TreeNode.arrayToTreeNode(new Integer[]{2, 1, 3, null, 4, null, 7});
        TreeNode xx = new LC617().mergeTrees(a, b);
        System.out.println(xx);
    }
}
